package com.znf4.controller.user;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.znf4.base.BaseReturnModel;
import com.znf4.enums.OperationStatusEnum;
import com.znf4.id.IdGenerator;
import com.znf4.user.order.entity.UserOrder;
import com.znf4.user.order.server.UserOrderServer;

/**
 * 用户信息 
 */
@RestController
@RequestMapping("/user/order")
public class UserOrderController {
	
	@Autowired
	private UserOrderServer userOrderServer ;
	
	@Autowired
	private IdGenerator idGenerator ;
	
	

	/**
	 * 函数功能说明 ： 添加用户基本信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/add", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> add(UserOrder userOrder , Model model) {
		userOrder.setId(idGenerator.getPaymentOrderId());
		userOrderServer.addUserOrder(userOrder);
		model.addAttribute("status", OperationStatusEnum.SUCCESS.getDesc() );
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}

	
	
	/**
	 * 函数功能说明 ： 修改用户信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/update", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> update(UserOrder userOrder , Model model) {
		userOrderServer.updateUserOrder(userOrder);
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}

	/**
	 * 函数功能说明 ： 删除用户信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delOne", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delOne(UserOrder userOrder , Model model) {
		userOrderServer.delOneUserOrder(userOrder); 
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}

	/**
	 * 函数功能说明 ： 删除多条用户信息
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/delAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> delAll(String[] ids  , Model model) {
		
		List<UserOrder> list = new ArrayList<>() ;
		for(int i=0 ; i < ids.length ; i ++ ){
			UserOrder userOrder = new UserOrder() ;
			userOrder.setId(ids[i]);
			list.add(userOrder) ;
		}
		userOrderServer.delAllUserOrder(list);
		return BaseReturnModel.getMapModel("success", "操作完成", "");
	}
	

	/**
	 * 函数功能说明 ： 获取多个用户信息
	 *
	 * @参数： @return
	 * @return String
	 * @throws
	 */
	@RequestMapping(value = "/queryAll", method = { RequestMethod.POST, RequestMethod.GET })
	public Map<String, Object> queryAll(UserOrder userOrder  , Model model) {
		List<UserOrder> list = userOrderServer.queryAll(userOrder);
		return BaseReturnModel.getMapModel("success", list , "");
	}
	
	

}
